package com.mxt.moviedemo.controller;

import com.mxt.moviedemo.entity.Actors;
import com.mxt.moviedemo.entity.Directors;
import com.mxt.moviedemo.service.ActorsService;
import com.mxt.moviedemo.service.DirectorsService;
import com.mxt.moviedemo.service.TicketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class InfoController {
    private static final Logger logger = LoggerFactory.getLogger(InfoController.class);
    @Autowired
    private ActorsService actorsService;

    @Autowired
    private DirectorsService directorsService;

    @Autowired
    private TicketService ticketService;

    @GetMapping("/actorsInfo")
    public String showActorsInfo(@RequestParam("aid") int aid,
                                 @RequestParam("username") String username,
                                 @RequestParam("keyword") String keyword,
                                 @RequestParam("pageSize") int pageSize,
                                 Model model) {
        // 根据演员 ID 获取演员信息
        Actors actor = actorsService.getActorById(aid);
        logger.info("Controller层获取到的演员信息: {}", actor);
        model.addAttribute("actor", actor);
        model.addAttribute("username", username);
        model.addAttribute("keyword", keyword);
        model.addAttribute("pageSize", pageSize);
        return "actorsInfo";
    }

    @GetMapping("/directorsInfo")
    public String showDirectorsInfo(@RequestParam("did") int did,
                                    @RequestParam("username") String username,
                                    @RequestParam("keyword") String keyword,
                                    @RequestParam("pageSize") int pageSize,
                                    Model model) {
        // 根据导演 ID 获取导演信息
        Directors director = directorsService.getDirectorById(did);
        model.addAttribute("director", director);
        model.addAttribute("username", username);
        model.addAttribute("keyword", keyword);
        model.addAttribute("pageSize", pageSize);
        return "directorsInfo";
    }


}